
#include "mypushbutton.h"
#include<QPropertyAnimation>

MyPushButton::MyPushButton(QString normalImage,QString pressImage)
{
    this->normalImagePath = normalImage;
    this->pressImagePath = pressImage;

    QPixmap pix;
    bool res = pix.load(this->normalImagePath);

    if(!res)
    {
        qDebug()<<"图片加载错误";
        return;
    }
    this->setFixedSize(pix.width(),pix.height());
    this->setStyleSheet("QPushButton{border:0px;}");
    this->setIcon(pix);
    this->setIconSize(QSize(pix.width(),pix.height()));
}


void MyPushButton::mousePressEvent(QMouseEvent*e)
{
    if(this->pressImagePath!=" ")
    {
        QPixmap pix;
        bool res = pix.load(this->pressImagePath);

        if(!res)
        {
            qDebug()<<"图片加载错误";
            return;
        }
        this->setFixedSize(pix.width(),pix.height());
        this->setStyleSheet("QPushButton{border:0px;}");
        this->setIcon(pix);
        this->setIconSize(QSize(pix.width(),pix.height()));
    }
    return QPushButton::mousePressEvent(e);
}


void MyPushButton::mouseReleaseEvent(QMouseEvent* e)
{
    if(this->pressImagePath!=" ")
    {
        QPixmap pix;
        bool res = pix.load(this->normalImagePath);

        if(!res)
        {
            qDebug()<<"图片加载错误";
            return;
        }
        this->setFixedSize(pix.width(),pix.height());
        this->setStyleSheet("QPushButton{border:0px;}");
        this->setIcon(pix);
        this->setIconSize(QSize(pix.width(),pix.height()));
    }
    return QPushButton::mouseReleaseEvent(e);
}
